﻿using ApiManage.Models.zyhModels;
using ApiManage.Service.MsSql.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace ApiManage.Service.MsSql.Service
{
    public class WorkProjectService : BaseService, IWorkProjectService
    {

        public List<WorkProject> GetList(Expression<Func<WorkProject, bool>> where) => _zyhContext.WorkProject.Where(where).ToList();

        public void Insert(WorkProject param)
        {
            _zyhContext.Add(param);
            _zyhContext.SaveChanges();
        }

        public void Update(WorkProject param)
        {
            var item = _zyhContext.WorkProject.FirstOrDefault(o => o.Id == param.Id);
            if (item != null)
            {
                item.Name = param.Name;
                item.Description = param.Description;
                item.Sort = param.Sort;
                item.Status = param.Status;
            }
            _zyhContext.SaveChanges();
        }

        public void Delete(int id)
        {
            var user = _zyhContext.WorkProject.FirstOrDefault(o => o.Id == id);
            if (user != null) user.Status = 9;
            _zyhContext.SaveChanges();
        }
    }
}
